<?php

namespace app\logic;

use app\components\helpers\MappingHelper;
use app\forms\ConfigForm;
use app\models\Config;

class ConfigLogic extends BaseLogic
{

    public static function view($param)
    {
        $form = static::_validate(new ConfigForm(), $param, 'view');
        $module = Config::getSystemKey();
        return Config::getList(['where' => ['module' => $module[$form['module']]], 'select' => '*']);

    }

    public static function update($param)
    {
        $form = static::_validate(new ConfigForm(), $param, 'update');
        /*前端数据格式未定，按原样返回更新*/
//        $module = Config::getSystemKey();
        foreach ($form['data'] as $value) {
            /*json 格式需要转换*/
            $id = $value['id'];
            unset($value['id'], $value['name']);
            $res = Config::updateDataById($value, $id);
        }
    }


}